﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.Configuration;
using System.Data.SqlClient;

/// <summary>
/// Summary description for NewDataAccess
/// </summary>
public class NewDataAccess
{
  string ConnStr = "";
  SqlConnection Con = null;
  SqlCommand Sqlcmd = null;

	public NewDataAccess()
	{
       ConnStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
  //   ConnStr = WebConfigurationManager.AppSettings["ConnectionString"];
    Con = new SqlConnection(ConnStr);
    Sqlcmd = new SqlCommand();
    Sqlcmd.Connection = Con;
	}

  public SqlDataReader GetData( string cmd )
  {
    using(Sqlcmd)
      {
      // Check Connection to open or close
        if(Con.State == ConnectionState.Open)
          Con.Close();
      //
          Con.Open();
          Sqlcmd.CommandText = cmd;
          return Sqlcmd.ExecuteReader(CommandBehavior.CloseConnection);
      }
  }

  public int ExcNonQuery( string cmd)
  {
    // Check Connection to open or close
    if (Con.State == ConnectionState.Open)
       Con.Close();
      using(Sqlcmd)
      {        
      //
       Con.Open();
       Sqlcmd.CommandText = cmd;
       int rs = Sqlcmd.ExecuteNonQuery();
          Con.Close();
          return rs;
      }
  }

  public string RemoveSpecicalChar( string Input)
  {
    return Input.Replace(Convert.ToChar(39), Convert.ToChar(32));
  }
}
